import http from './http.js'
import qs from 'qs'
//根据分类id获取分类
export function reqCategory (categoryId) {
  return http({
    method: 'get',
    url: `/manage/category/info`,
    params: { categoryId },
  })
}
//获取列表数据
export function list (pageNum, pageSize, searchType, searchName) {
  return http({
    method: 'get',
    url: `/manage/product/search`,
    params: { pageNum, pageSize, searchType, searchName },
  })
}
//获取产品类型数据
export function getCategorys () {
  return http({
    method: 'get',
    url: `/manage/category/all`,
  })
}
//添加，更新
export function addOrUpdate (product) {
  return http({
    method: 'post',
    url: '/manage/product/' + (product._id ? 'update' : 'add'),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({ ...product }),
  })
}
//上/下架
export function reqUpdateProductStatus (productId, status) {
  return http({
    method: 'post',
    url: '/manage/product/updateStatus',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({ productId, status }),
  })
}
//删除图片
export function reqDeleteImg (name) {
  return http({
    method: 'post',
    url: '/manage/img/delete',
  })
}
//id获取商品信息
export function findOneById (productId) {
  return http({
    method: 'GET',
    url: `/manage/product/findOneById/${productId}`
  })
}